<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div>
        <div id="app">
             <div>
                 <label>
                     id
                     <input type="text" v-model='id'>
                 </label>
                 <label>
                    name
                    <input type="text" v-model='name'>
                </label>
                <button @click='add'>点击添加</button>
                <h1>{{id}}----{{name}}</h1>
                
             </div>
            <ul>
                <!-- 在工作中 并非不能用key绑定index  向前推送的情况下用index慎重 -->
                <li v-for='(item,index) in list'  :key='item.id'>
                    <input type="checkbox">
                    id:{{item.id}} ---- 武侠人物姓名:{{item.name}}
                </li>
            </ul>
        </div>

    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>

        var vm = new Vue({
            // 监管的容器 
            el: '#app',
            // 数据定义
            data: {
                msg: 'helloworld',
                id:'',
                name:'',
                list: [
                    {
                        id: 1,
                        name: '张无忌'
                    },
                    {
                        id: 2,
                        name: '令狐冲'
                    },
                    {
                        id: 3,
                        name: '杨过'
                    },
                    {
                        id: 4,
                        name: '乔峰'
                    }
                ]
            },
            methods:{
                add() {
                    console.log('add fn') 
                    var temobj = {id:this.id,name:this.name} 
                    // this.list.push(temobj)
                    this.list.unshift(temobj)
                }
            }
        })

        console.log('vm', vm)



    </script>
</body>

</html>